<template>
	<view class="content">
		<view class="price">
			<view class="title">总运费</view>
			<view class="num">
				<view>
					<text class="val">{{(info.freight*1).toFixed(2)}}</text>元
				</view>
				<text>运费=拉料吨数*运费单价</text>
			</view>
		</view>
		<view class="address">
			<view class="date">
				<text>用车 <text class="time">{{info.plan_beg_date}}</text> </text>
				<!-- <text style="color:#666 ;">全程277km</text> -->
			</view>
			<view class="list">
				<view class="item">
					<text class="lefticon">装</text>
					<text class="mid">{{info.beg_land}}</text>
					<view class="icon iconfont icon-daohang"></view>
				</view>
				<view class="item">
					<text class="line">|</text>
				</view>
				<view class="item">
					<text class="lefticon" style="background-color: #ff6700;">卸</text>
					<text class="mid">{{info.consignee_address}}</text>
					<view class="icon iconfont icon-daohang"></view>
				</view>
			</view>
		</view>
		<view class="info">
			<view class="title">订单信息 <view class="icon iconfont icon-guanyu"></view>
			</view>
			<view class="val">
				<text>货物名称</text>
				<text>{{info.goods_name}}</text>
			</view>
			<view class="val">
				<text>货物重量</text>
				<text>{{(info.goods_num*1).toFixed(4)}}{{info.goods_spec}}</text>
			</view>
			<!-- <view class="val">
				<text>运费单价</text>
				<text></text>
			</view> -->
		</view>
		<view class="info">
			<view class="title">计划时间 <view class="icon iconfont icon-guanyu"></view>
			</view>
			<view class="val">
				<text>计划装货时间</text>
				<text>{{info.plan_beg_date}}</text>
			</view>
			<view class="val">
				<text>计划到货时间</text>
				<text>{{info.plan_end_date}}</text>
			</view>
		</view>
		<view class=" fixedbtn" v-if="info.signer_status==0">
			<view class="btnbox">
				<view class="btn" @tap="dialogToggle">拒单</view>
				<view class="btn search" @tap="dialogToggle2">接单</view>
			</view>
		</view>
		<!-- 拒单弹窗 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确认"  content="是否确认拒单？"
				@confirm="refuse"></uni-popup-dialog>
		</uni-popup>
		<!-- 接单弹窗 -->
		<uni-popup ref="alertDialog2" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确认"  content="是否确认接单？"
				@confirm="receive"></uni-popup-dialog>
		</uni-popup>

	</view>
</template>

<script setup>
	import {
		getOrderDetail,
		receiveOrder,
		orderRefuse
	} from '../../network/index.js';
	import {
		ref,
		reactive,
		onMounted
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app';
	onLoad((res) => {
		getDetail(res.id)
		id.value = res.id
	})
	const id = ref('')
	const info = reactive({})
	const enquiry = reactive({})
	const getDetail = (id) => {
		let data = {
			id: id
		}
		getOrderDetail(data).then(res => {
			Object.assign(info, res.data.data)
			Object.assign(enquiry, res.data.data.enquiry)
		})
	}
	const alertDialog = ref(null)
	const refuseId = ref('')
	const dialogToggle = (type) => {
		alertDialog.value.open()
		refuseId.value = id
	}
	const refuse = () => {
		let data = {
			id: refuseId.value
		}
		orderRefuse(data).then(res => {
			uni.showToast({
				title: '拒单成功'
			})
			setTimeout(() => {
				uni.switchTab({
					url: '/pages/index/index'
				})
			}, 300)
		})
	}
	const alertDialog2 = ref(null)
	const dialogToggle2 = (type) => {
		alertDialog2.value.open()
	}
	const receive = () => {
		let data = {
			id: id.value
		}
		receiveOrder(data).then(res => {
			uni.showToast({
				title: '接单成功'
			})
			setTimeout(() => {
				uni.navigateBack({
					delta:1
				})
			}, 300)
		})
	}
</script>

<style lang="scss">
	.content {
		padding-bottom: 150rpx;
		box-sizing: border-box;
		background-color: #fff;
	}

	.price {
		padding: 20rpx 40rpx;
		box-sizing: border-box;
		margin-top: 2rpx;
		border-top: 2rpx solid #f7f7f7;

		.title {
			color: #333;
			font-size: 32rpx;
			font-weight: bold;
		}

		.num {
			font-size: 28rpx;
			color: #ff6700;
			display: flex;
			justify-content: space-between;
			margin-top: 20rpx;
			align-items: center;

			.val {
				font-size: 50rpx;
			}
		}
	}

	.address {
		border-top: 2rpx solid #f7f7f7;
		padding: 20rpx 40rpx;
		box-sizing: border-box;
		position: relative;
		margin: 20rpx 0;

		.date {
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 28rpx;

			.time {
				color: #ff6700;
				margin-left: 20rpx;
			}
		}

		.list {
			margin-top: 20rpx;
			display: flex;
			flex-direction: column;
			gap: 10rpx;
			font-size: 28rpx;

			.item {
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				align-items: flex-start;

				.lefticon {
					width: 36rpx;
					height: 36rpx;
					border-radius: 18rpx;
					line-height: 36rpx;
					font-size: 24rpx;
					text-align: center;
					background-color: #3cc51f;
					color: #fff;
					margin-top: 6rpx;
				}

				.line {
					padding: 0 16rpx;
				}

				.mid {
					width: 540rpx;
					margin-top: 4rpx;
				}

				.icon {
					font-size: 40rpx;
					margin-top: 6rpx;
				}
			}
		}
	}

	.info {
		padding: 20rpx 40rpx;
		box-sizing: border-box;
		border-top: 2rpx solid #f7f7f7;

		.title {
			font-size: 32rpx;
			display: flex;
			justify-content: flex-start;
			font-weight: bold;
			line-height: 60rpx;
			gap: 20rpx;
		}

		.icon {
			font-size: 40rpx;
			color: #ff6700;
		}

		.val {
			font-size: 28rpx;
			color: #333;
			line-height: 50rpx;
			display: flex;
			justify-content: space-between;
		}
	}

	.fixedbtn {
		width: 100%;
		position: fixed;
		bottom: 0;
		left: 0;

		.btnbox {
			border-top: 2rpx solid #f7f7f7;
			width: 100%;
			padding: 30rpx 0;
			display: flex;
			justify-content: space-around;

			.btn {
				width: 400rpx;
				height: 60rpx;
				background-color: #f8f8f8;
				line-height: 60rpx;
				text-align: center;
				border-radius: 12rpx;
				font-size: 26rpx;
			}

			.search {
				background-color: #ffc400;
			}
		}
	}
</style>